package com.sktlab.bizconfmobile.model.manager;

import java.util.ArrayList;
import java.util.HashMap;

import com.sktlab.bizconfmobile.model.Conference;
import com.sktlab.bizconfmobile.model.ConferenceAccount;
import com.sktlab.bizconfmobile.util.Util;

public class CommunicationManager {

	public static final String TAG = "CommunicationManager";
	
	private ConferenceAccount mActiveAccount;
	//private Conference mActiveConference;

	// used to store the active conference in current bridge
	private HashMap<String, Conference> mActiveConfs;

	private ArrayList<String> outCallPartyIds;
	
	private static class InstanceHolder {

		private final static CommunicationManager instance = new CommunicationManager();
	}

	private CommunicationManager() {
		
		mActiveConfs = new HashMap<String, Conference>();
		outCallPartyIds = new ArrayList<String>();
	}
	
	public static CommunicationManager getInstance() {

		return InstanceHolder.instance;
	}
	
	public ConferenceAccount getActiveAccount() {
		return mActiveAccount;
	}

	public void setActiveAccount(ConferenceAccount mActiveAccount) {
		this.mActiveAccount = mActiveAccount;
	}

	public Conference getActiveConfByKey(String key) {

		if (mActiveConfs.containsKey(key)) {

			return mActiveConfs.get(key);
		}

		return null;
	}

	public void putActiveConference(Conference conf) {

		if (!Util.isEmpty(conf)) {

			String key = conf.getAttr().getConfName();

			Util.BIZ_CONF_DEBUG(TAG, "active conf key: " + key);

			if (!Util.isEmpty(key) && !mActiveConfs.containsKey(key)) {

				mActiveConfs.put(key, conf);
			} else {

				Util.BIZ_CONF_DEBUG(TAG,
						"active conference's conf Id is null or had been in map");
			}

		} else {

			Util.BIZ_CONF_DEBUG(TAG, "active conference is null");
		}
	}

	public HashMap<String, Conference> getActiveConfs() {
		return mActiveConfs;
	}

	public void setActiveConfs(HashMap<String, Conference> mActiveConfs) {

		this.mActiveConfs = mActiveConfs;
	}

	public void clearActiveConfs() {

		mActiveConfs.clear();
	}

	public void addOutCallPartyId(String partyId) {

		outCallPartyIds.add(partyId);
	}

	public ArrayList<String> getOutCallPartyIds() {
		return outCallPartyIds;
	}

	public void setOutCallPartyIds(ArrayList<String> outCallPartyIds) {
		this.outCallPartyIds = outCallPartyIds;
	}
}
